package com.somnus.androidkotlindemo.callback

import android.support.v7.util.DiffUtil

/**
 * Created by Somnus on 2019/5/22.
 */
class DiffUtilsCallback(_oldList: List<String>, _newList: MutableList<String>) : DiffUtil.Callback() {
    var mOldList: List<String> = _oldList
    var mNewList: List<String> = _newList

    /**
     * 判断是否是同一个Item。
     */
    override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
        return mOldList.get(oldItemPosition).equals(mNewList.get(newItemPosition))
    }

    override fun getOldListSize(): Int {
        return mOldList.size
    }

    override fun getNewListSize(): Int {
        return mNewList.size
    }

    /**
     * 如果是通一个Item，此方法用于判断是否同一个 Item 的内容也相同。
     */
    override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {

        val oldStr = mOldList.get(oldItemPosition)
        val newStr = mNewList.get(newItemPosition)
        return oldStr.equals(newStr)
    }


}